<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"	
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:cc="http://java.sun.com/jsf/composite">

<cc:interface componentType="org.jboss.seam.faces.InputContainer">
	<cc:attribute name="modalAction" required="true" />
	<cc:attribute name="legend" required="true" />
	
	<!-- Atributos da tag sig:dialog -->
	<cc:attribute name="columns" required="true" shortDescription="Colunas que serão exibidas no modal." />
	<cc:attribute name="filters" required="false" shortDescription="Filtros da consulta." />
	<cc:attribute name="fields" required="false" shortDescription="Campos para Inclusão/Edição." />	
	<cc:attribute name="header" required="true" />
	<cc:attribute name="height" required="false" />
	<cc:attribute name="id" required="true" />
	<cc:attribute name="list" required="true" />
	<cc:attribute name="rows" required="false" />
	<cc:attribute name="selection" required="true" />
	<cc:attribute name="selectionMode" required="false" />
	<cc:attribute name="selectionType" required="false" />	
	<cc:attribute name="update" required="true" />
	<cc:attribute name="width" required="false" />
</cc:interface>

<cc:implementation xmlns:sig="http://java.sun.com/jsf/composite/components">
	<p:fieldset id="fieldset#{cc.attrs.id}" legend="#{cc.attrs.legend}" style="width: 600px">
	
		<p:commandLink
			action="#{cc.attrs.list.startModal()}"
			oncomplete="PF('dialogModal#{cc.attrs.id}').show();"
			partialSubmit="true"
			process="@this"
			update=":formCrud:#{cc.attrs.id}:#{cc.attrs.id}:panelDataTableModal#{cc.attrs.id}"
			value="+ #{messages['link.include']}" styleClass="linkIncluirSecundario"
			rendered="#{cc.attrs.list != null}" />
			
		<p:commandLink
			action="#{cc.attrs.modalAction.startModal()}"
			oncomplete="PF('dialogModal#{cc.attrs.id}').show();"
			partialSubmit="true"
			process="@this"
			update=":formCrud:#{cc.attrs.id}:#{cc.attrs.id}:panelDataTableModal#{cc.attrs.id}"
			value="+ #{messages['link.include']}" styleClass="linkIncluirSecundario"
			rendered="#{cc.attrs.modalAction != null and cc.attrs.list == null}" />
			
		<p:dataTable
			id="dataTable#{cc.attrs.id}" value="#{cc.attrs.selection}" var="entity" emptyMessage="" rowKey="#{entity.id}">
	        
	        <p:ajax event="rowSelect" update="dataTable#{cc.attrs.id}" immediate="true" partialSubmit="true" />
	        <p:ajax event="rowUnselect" update="dataTable#{cc.attrs.id}" immediate="true" partialSubmit="true" />
	        				        
			<ui:include src="#{cc.attrs.columns}" />
		    
		    <p:column headerText="Ação">
		    	<p:commandLink partialSubmit="true" process="@this" update="dataTable#{cc.attrs.id}" action="#{cc.attrs.modalAction.remove(entity)}">
		        	<h:graphicImage library="images" name="deletar.png" alt="Excluir" title="Excluir" />
		        </p:commandLink>
		    </p:column>			    
			
		</p:dataTable>
				
	</p:fieldset>
	
	<sig:dialog
		columns="#{cc.attrs.columns}"
		filters="#{cc.attrs.filters}"
		fields="#{cc.attrs.fields}"
		modalAction="#{cc.attrs.modalAction}"
		header="#{cc.attrs.header}"
		id="#{cc.attrs.id}"
		list="#{cc.attrs.list}"
		selection="#{cc.attrs.selection}"
		selectionType="#{cc.attrs.selectionType}"
		update="#{cc.attrs.update}"
	 />
	 
</cc:implementation>
</html>